<template>
  <el-dialog :visible.sync="value" :before-close="cancel">
    <template slot="title">
      {{isCreated ? '添加' : '编辑'}}手续费方案
    </template>
    <el-form :model="form" :rules="refRule" ref="refForm" :label-width="formLabelWidth">
      <el-form-item label="手续费方案名" prop="name">
        <el-col :span="16">
          <el-input v-model="form.name" @keyup.enter.native="doSave({action: 'saveForm', form: 'refForm'})"></el-input>
        </el-col>
      </el-form-item>

      <el-form-item label="状态" prop="status">
        <el-col :span="16">
          <el-select v-model="form.status">
            <el-option
              v-for="item in consts.COMMISSION_STATUS"
              :label="item.title"
              :value="item.value"
              :key="item.value"
            ></el-option>
          </el-select>
        </el-col>
      </el-form-item>
      <!-- <el-form-item label="默认佣金模式" prop="status">
        <el-col :span="16">
          <el-radio v-model="form.radio" >默认</el-radio>
        </el-col>
      </el-form-item> -->
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="doSave({action: 'saveForm', form: 'refForm'})">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>

import { form } from '@/build';
import { editCommission } from '@/services/api/commission';

export default {
  name: 'commission-config-dialog',
  props: ['value', 'id', 'rowData'],
  mixins: [form],
  data() {
    return {
      formLabelWidth: '180px',
      keywords: !this.id ? '新增' : '编辑',
      form: {
        name: undefined,
        status: undefined,
        radio: undefined,
        ...this.rowData,
      },
      refRule: {
        name: [
          { required: true, message: '手续费方案名不能为空' },
          { max: 45, message: '不能超过45个字符' },
        ],
        status: [
          { required: true, message: '状态为必选项' },
        ],
      },
    };
  },

  computed: {
    isCreated() {
      return !this.id;
    },
  },
  mounted() {
    this.bindSave(editCommission, 'saveForm', 'form', {
      afterSuccess: () => {
        this.cancel();
        this.$parent.getAll();
      },
    });
  },
  methods: {
    cancel() {
      this.$emit('input', false);
    },
  },

};
</script>

<style lang="scss" scoped>

</style>
